package pers.mobian.springthird;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import pers.mobian.springfirst.firstTest.User;

/**
 * @Date 2021/7/10 10:54
 * @Created mobian
 * @Description
 */
public class BeanFactoryTest1 {
	public static void main(String[] args) {

		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
		// beanFactory 直接注册对应的对象
//		beanFactory.registerSingleton("user",  new User());

		// beanFactory 注册对应的beanDefinition
		AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		beanDefinition.setBeanClass(User.class);
		beanFactory.registerBeanDefinition("user",beanDefinition);


		User user = beanFactory.getBean("user", User.class);
		System.out.println(user);

		User user1 = new User();
		System.out.println(user1);

	}
}
